// 获取订单来源
export const platformStr = (str) => {
	switch (str) {
		case "baidu":
			return "商城-润秘康";
		case "2":
			return "京东";
		case "3":
			return "拼多多";
		default:
			return
	}
};

export const platformStrDetails = (str) => {
	switch (str) {
		case "baidu":
			return "百度健康-润秘康官方旗舰店";
		case "2":
			return "京东";
		case "3":
			return "拼多多";
		default:
			return
	}
};


// 状态码处理
// 状态  编码描述
// 130  交易关闭 退款完成、用户取消等等，逆向流程的终态
// 140  购药订单:用户已支付，待商家发货
// 143  商家已接单
// 146  商家拒绝接单
// 150  购药订单商家已发货
// 160  用户申请退款，待商家审核
// 190  B2C订单为已签收(物流轨迹返回签收状态);O20订单为商家确认送达
// 200  购药订单:用户确认收货，交易完成
// 999  其他状态

// 根据不同的状态 设置不同的字体颜色
export const orderStatusStr = (status) => {
	switch (status) {
		case 130:
			return {
				text: "交易关闭",
					color: "#e06d6d",
			};
		case 140:
			return {
				text: "待商家发货",
					color: "orange",
			};
		case 143:
			return {
				text: "商家已接单",
					color: "green",
			};
		case 146:
			return {
				text: "商家拒绝接单",
					color: "red",
			};
		case 150:
			return {
				text: "商家已发货",
					color: "orange",
			};
		case 160:
			return {
				text: "用户申请退款",
					color: "orange",
			};
		case 190:
			return {
				text: "已签收",
					color: "green",
			};
		case 200:
			return {
				text: "交易完成",
					color: "green",
			};
		case 999:
			return {
				text: "其他状态",
					color: "orange",
			};
		default:
			return {
				text: "未知状态",
					color: "orange",
			};
	}
}

// 商品品牌
export const getStr = (str) => {
	if (!str) return;
	return str.split(" ").slice(0, 2).join(" ");
};

// 订单来源
export const orderFrom = (str) => {
	if (!str) return;
	return str.split("-").pop();
};

// 置顶状态
// 1 跟踪置顶
// 2 客户投诉
// 3 客户退货
// 4 客户差评
export const topStatusList = [{
		label: "跟踪置顶",
		value: 1,
		className: "yellow-class",
	},
	{
		label: "客户投诉",
		value: 2,
		className: "red-class",
	},
	{
		label: "客户退货",
		value: 3,
		className: "red-class",
	},
	{
		label: "客户差评",
		value: 4,
		className: "black-class",
	},
];

// 根据订单 生成面单备注
// 传递数组和路由前缀
export const applyRemarks = (cloneOrders, prefix) => {
	const str = prefix
	cloneOrders.forEach((o) => {
		let shopStr = str + "-";
		// 判断是否是多包裹
		if (o.isMultiPackage) {
			shopStr += `共${o.childrens.length}个包裹 `;
		} else {
			// // newStr + 订单金额 + 商品1数量 + 商品2数量
			shopStr += `实付金额：${o.actualPrice?.toFixed(2)}元 - `;
			o.productCollection?.forEach((item, index) => {
				if (!item.num) return;
				let productName = item.productName
				let shopNum = item.num
				console.log(' item.productName===>  ', item.productName, o, item)
				// 平台订单总量和复购订单总量计算方式不一样
				if (o.orderType == 1) {
					productName = getStr(item.productName || o.productName);
					shopNum = item.totalUnitNum
				}
				shopStr += `商品${productName}*${shopNum}` + (o.productCollection.length - 1 ===
					index ? '' : ' - ');
			});
		}
		o.remark = shopStr;
	});
};